<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue中的路由基础</title>
    <style>
      .router-link-active{
          color:red;
      }
    </style>
</head>

<body>
    <div id="app">
        <p>
            <!-- 使用 router-link 组件来导航. -->
            <!-- 通过传入 `to` 属性指定链接. -->
            <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
            <router-link to="/home">主页</router-link>
            <router-link to="/news">新闻</router-link>
        </p>

        <div>
            <!-- 路由出口 -->
            <!-- 路由匹配到的组件将渲染在这里 -->
            <router-view></router-view>
        </div>
    </div>
    <script src="node_modules/vue/dist/vue.js"></script>
    <script src="node_modules/vue-router/dist/vue-router.js"></script>

    <script>
        // 1.创建所要用到的组件
        var Home = Vue.extend({
            template: '<h2>我是主页</h2>'
        });
        var News = Vue.extend({
            template: '<h2>我是新闻页</h2>'
        });
        // 2.准备路由
        var router = new VueRouter({
            routes: [
                {
                    path: '/home',
                    component: Home
                },
                {
                    path: '/news',
                    component: News
                }
            ]
        });
        //创建根组件，并将路由挂载到上面
        var App = new Vue({
            el: "#app",
            router: router
        });
       
    </script>
</body>

</html>